package com.yztc.administrator.meishi.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;

public class Httputils {
	private static byte[] dates;
	//从网络上获取请求
	public static byte[] getpath(String path) {
			try {
				//创建URL对象
				URL url=new URL(path);
				//从网络获取数据
				HttpURLConnection open = (HttpURLConnection) url.openConnection();
				open.setRequestMethod("GET");
				open.setConnectTimeout(5000);
				
					InputStream is = open.getInputStream();
					ByteArrayOutputStream bas = new ByteArrayOutputStream();
					int len = 0;
					byte[] b = new byte[1024];
					while ((len = is.read(b)) != -1) {
						bas.write(b, 0, len);
						bas.flush();
					}
					dates = bas.toByteArray();
					
					
				
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ProtocolException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return dates;
	
		
		
		
	
		
		
		
		
	
		
		
		
	}
}
